package com.intellagric.controller.module.ift_ctrl_equipment;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.pojo.IftCtrlEquipmentType;
import com.intellagric.service.iftmonitor.ift_ctrl_equipment.CtrlEquipmentTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/23
 * @DESC： 控制设备类型管理
 */
@Controller
public class CtrlEquipmentTypeController {

    @Autowired
    private CtrlEquipmentTypeService ctrlEquipmentTypeService;

    /**
     * 添加控制设备类型信息
     * @Param ctrlEquipmentType
     * @return ResponseMessage
     */
    @RequestMapping("/ctrlequipment/type/add")
    @ResponseBody
    public ResponseMessage add(IftCtrlEquipmentType ctrlEquipmentType) {
        ctrlEquipmentType.setId(UUID.randomUUID().toString().replaceAll("-",""));
        ctrlEquipmentType.setCreateDate(new Date());
        ctrlEquipmentType.setUpdateDate(new Date());
        return ctrlEquipmentTypeService.addCtrlEquipmentType(ctrlEquipmentType);
    }


    /**
     * 删除控制设备类型信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/ctrlequipment/type/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return ctrlEquipmentTypeService.deleteCtrlEquipmentType(id);
    }

    /**
     * 修改控制设备类型信息
     * @Param
     * @return ResponseMessage
     */
    @RequestMapping("/ctrlequipment/type/edit")
    @ResponseBody
    public ResponseMessage edit(IftCtrlEquipmentType ctrlEquipmentType) {
        ctrlEquipmentType.setUpdateDate(new Date());
        ctrlEquipmentType.setCreateDate(null);
        return ctrlEquipmentTypeService.editCtrlEquipmentType(ctrlEquipmentType);
    }

    /**
     * 查询控制设备类型信息
     * @return IftCtrlEquipmentType
     */
    @RequestMapping("/ctrlequipment/type/{id}")
    @ResponseBody
    public IftCtrlEquipmentType get(@PathVariable String id) {
        return ctrlEquipmentTypeService.getCtrlEquipmentTypeById(id);
    }

    /**
     * 查询控制设备类型树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/ctrlequipment/type/tree")
    @ResponseBody
    public LayuiDataGridResult getTree() {
        return ctrlEquipmentTypeService.getCtrlEquipmentTypeTree();
    }

    /**
     * 查询控制设备类型树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/ctrlequipment/type/tree/select")
    @ResponseBody
    public List<IftCtrlEquipmentType> getTreeSelect() {
        return ctrlEquipmentTypeService.getCtrlEquipmentTypeTree().getData();
    }

    /**
     * 查询控制设备类型信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/ctrlequipment/type/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return ctrlEquipmentTypeService.getCtrlEquipmentTypeList();
    }

}
